﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KingerRobot.MexicoSailunMDC.SpiService;

internal class BWmsBuildingNotInWareStatus : IWmsBuildingNotInWareStatus
{
    public int UpdateBuildingStatus(string buildCode, string material, string remark, int status)
    {
        var result = 0;
        var db = Db.Default;
        var builds = db.POWmsBuildingNotInWareStatuss.Where(t => t.BuildingCode == buildCode).FirstOrDefault();
        if (builds is not null)
        {
              db.POWmsBuildingNotInWareStatuss.Where(t => t.BuildingCode == buildCode).Update( new POWmsBuildingNotInWareStatus()
            {
                BuildingCode = buildCode,
                EquipMaterial = material,
                ReamrkMemo = remark,
                EquipStatus = status,

            });
            result = db.SaveChanges();
        }
        return result;
    }
    public int UpdateBuildingStatusByMaterialCode(string material, string remark, int status)
    {
        var result = 0;
        var db = Db.Default;
        var builds = db.POWmsBuildingNotInWareStatuss.Where(t => t.EquipMaterial == material).FirstOrDefault();
        if (builds is not null)
        {
             db.POWmsBuildingNotInWareStatuss.Where(t => t.EquipMaterial == material).Update( new POWmsBuildingNotInWareStatus()
            {
                //BuildingCode = buildCode,
                //EquipMaterial = material,
                ReamrkMemo = remark,
                EquipStatus = status,

            });
            result=db.SaveChanges();
        }
        return result;
    }
    public POWmsBuildingNotInWareStatus GetBuildingByCode(string buildCode)
    {
        var db = Db.Default;
        var result = db.POWmsBuildingNotInWareStatuss.Where(t => t.BuildingCode == buildCode).FirstOrDefault();
        return result;
    }

    public int UpdateBuildMaterialCode(string buildCode, string MaterialCode)
    {
        var db = Db.Default;
        db.POWmsBuildingNotInWareStatuss.Where(t => t.BuildingCode == buildCode).Update( new POWmsBuildingNotInWareStatus
        {
            EquipMaterial = MaterialCode,
        });
        var result = db.SaveChanges();
        return result;
    }




    public int GetHighStatus()
    {
        var db = Db.Default;
        var result = db.POWmsBuildingNotInWareStatuss.Where(t => t.DisabledType == (int)EnumBuildDisabledType.NoHighLoc).Count();
        return result;

    }
}

